<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
		<title></title>
	</head>
	<body>
		<div id="msg">跳转中...</div>
		<script type="text/javascript">
			//获取url地址的参数
			function getQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]);
				return null;
			};
			// 模仿a标签跳转
			function imitateAClick(url) {
				let aEle = document.createElement("a");
				aEle.setAttribute("href", url);
				aEle.setAttribute("target", "_blank");
				aEle.setAttribute("id", "previewJumpEle");
				if (!document.getElementById("previewJumpEle")) {
					document.body.appendChild(aEle);
				}
				aEle.click();
				(aEle.remove && aEle.remove()) || (aEle.removeNode && aEle.removeNode(true));
			}
			setTimeout(() => {
				const _url = getQueryString('callbackUrl');
				const type = getQueryString('type');
				console.log(_url, type)
				switch (+type) {
					case 0:
						document.getElementById('msg').innerText = `重定向window.location.replace...${_url}`;
						window.location.replace(_url);
						// 结论：只会在iframe内部跳转（×）
						break;
					case 1:
						document.getElementById('msg').innerText = `重定向top.window.location.replace...${_url}`;
						top.window.location.replace(_url);
						// 结论：全局改变地址 （√）
						break;
					case 2:
						document.getElementById('msg').innerText = `模拟a标签跳转...${_url}`;
						imitateAClick(_url);
						// 结论：会被拦截 （×）
						break;
					case 3:
						document.getElementById('msg').innerText = `window.location.href...${_url}`;
						window.location.href = _url;
						// 结论：只会在iframe内部跳转（×）
						break;
					case 4:
						document.getElementById('msg').innerText = `top.window.location.href...${_url}`;
						top.window.location.href = _url;
						// 结论：全局改变地址 （√）
						break;
					case 5:
						document.getElementById('msg').innerText = `window.open()打开...${_url}`;
						window.open(_url);
						// 结论：会被拦截 （×）
						break;
					case 6:
						document.getElementById('msg').innerText = `top.window.open()打开...${_url}`;
						top.window.open(_url);
						// 结论：会被拦截 （×）
						break;
				}
				// 最后的结论：top.window.location.replace(_url); 或 top.window.location.href = _url;  都可以用
			}, 2000)
		</script>
	</body>
</html>
